package web.fabrimind.pm.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import web.fabrimind.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import web.fabrimind.pm.mapper.WorkOrderMapper;
import web.fabrimind.pm.domain.WorkOrder;
import web.fabrimind.pm.service.IWorkOrderService;

/**
 * 生产工单Service业务层处理
 * 
 * @author zhihui
 * @date 2025-03-25
 */
@Service
public class WorkOrderServiceImpl implements IWorkOrderService 
{
    @Autowired
    private WorkOrderMapper workOrderMapper;

    /**
     * 查询生产工单
     * 
     * @param orderId 生产工单主键
     * @return 生产工单
     */
    @Override
    public WorkOrder selectWorkOrderByOrderId(Long orderId)
    {
        return workOrderMapper.selectWorkOrderByOrderId(orderId);
    }

    /**
     * 查询生产工单列表
     * 
     * @param workOrder 生产工单
     * @return 生产工单
     */
    @Override
    public List<WorkOrder> selectWorkOrderList(WorkOrder workOrder)
    {
        return workOrderMapper.selectWorkOrderList(workOrder);
    }

    /**
     * 新增生产工单
     * 
     * @param workOrder 生产工单
     * @return 结果
     */
    @Override
    public int insertWorkOrder(WorkOrder workOrder)
    {
        workOrder.setCreateTime(DateUtils.getNowDate());
        return workOrderMapper.insertWorkOrder(workOrder);
    }

    /**
     * 修改生产工单
     * 
     * @param workOrder 生产工单
     * @return 结果
     */
    @Override
    public int updateWorkOrder(WorkOrder workOrder)
    {
        workOrder.setUpdateTime(DateUtils.getNowDate());
        return workOrderMapper.updateWorkOrder(workOrder);
    }

    /**
     * 批量删除生产工单
     * 
     * @param orderIds 需要删除的生产工单主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteWorkOrderByOrderIds(Long[] orderIds)
    {
        return workOrderMapper.deleteWorkOrderByOrderIds(orderIds);
    }

    /**
     * 删除生产工单信息
     * 
     * @param orderId 生产工单主键
     * @return 结果
     */
    @Override
    public int deleteWorkOrderByOrderId(Long orderId)
    {
        return workOrderMapper.deleteWorkOrderByOrderId(orderId);
    }

    /**
     * 查询关联计划列表（不分页）
     */
    @Override
    public List<WorkOrder> selectPlanList(WorkOrder workOrder) {
        return workOrderMapper.selectPlanList(workOrder);
    }
}
